﻿using System;
using System.Configuration;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 系统日志
    /// </summary>
    public sealed class EventLoggerElement : LoggerElement
    {
        /// <summary>
        /// 保存日志的主机名，默认为本机
        /// </summary>
        [ConfigurationProperty("host", IsRequired = false, DefaultValue = ".")]
        public string Host
        {
            get
            {
                return (string)this["host"];
            }
        }

        /// <summary>
        /// 日志名称
        /// </summary>
        [ConfigurationProperty("logName", IsRequired = false, DefaultValue = "Application")]
        public string LogName
        {
            get
            {
                return (string)this["logName"];
            }
        }

        /// <summary>
        /// 日志分类
        /// </summary>
        [ConfigurationProperty("category", IsRequired = false, DefaultValue = 0)]
        public int Category
        {
            get
            {
                return (int)this["category"];
            }
        }

        /// <summary>
        /// 事件源
        /// </summary>
        [ConfigurationProperty("eventSource", IsRequired = true)]
        public string EventSource
        {
            get
            {
                return (string)this["eventSource"];
            }
        }

        /// <summary>
        /// 事件ID
        /// </summary>
        [ConfigurationProperty("eventId", IsRequired = true)]
        public int EventId
        {
            get
            {
                return (int)this["eventId"];
            }
        }

        /// <summary>
        /// 具有管理员权限的账户
        /// </summary>
        [ConfigurationProperty("account")]
        public AccountElement Account
        {
            get
            {
                return (AccountElement)this["account"];
            }
        }

        /// <summary>
        /// 获取系统日志对象
        /// </summary>
        /// <returns></returns>
        public override ILogger GetLogger()
        {
            EventLogger el = new EventLogger(this.EventSource, this.EventId);
            el.Host = this.Host;
            el.UserName = this.Account.UserName;
            el.Domain = this.Account.Domain;
            el.Password = this.Account.Password;
            el.LogName = this.LogName;
            el.Category = this.Category;
            return el;
        }
    }
}
